<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Convert a phar archive to a non-executable tar or zip file</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.construct.html">Phar::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.converttoexecutable.html">Phar::convertToExecutable</a></div>
 <div class="up"><a href="class.phar.html">Phar</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="phar.converttodata" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Phar::convertToData</h1>
  <p class="verinfo">(PHP &gt;= 5.3.0, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">Phar::convertToData</span> &mdash; <span class="dc-title">Convert a phar archive to a non-executable tar or zip file</span></p>

 </div>


 <div class="refsect1 description" id="refsect1-phar.converttodata-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="class.phardata.html" class="type PharData">PharData</a></span> <span class="methodname"><strong>Phar::convertToData</strong></span>
    ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code><span class="initializer"> = 9021976</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$compression</code><span class="initializer"> = 9021976</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$extension</code></span>
  ]]] )</div>


  <p class="para rdfs-comment">
   This method is used to convert an executable phar archive to either a
   tar or zip file.  To make the tar or zip non-executable, the phar
   stub and phar alias files are removed from the newly created archive.
  </p>
  <p class="para">
   If no changes are specified, this method throws a <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a>
   if the archive is in phar file format.  For archives in tar or zip file format,
   this method converts the archive to a non-executable archive.
  </p>
  <p class="para">
   If successful, the method creates a new archive on disk and returns a <a href="class.phardata.html" class="classname">PharData</a>
   object.  The old archive is not removed from disk, and should be done manually after
   the process has finished.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phar.converttodata-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">format</code></em></dt>

     <dd>

      <p class="para">
       This should be one of <em>Phar::TAR</em>
       or <em>Phar::ZIP</em>.  If set to <strong><code>NULL</code></strong>, the existing file format
       will be preserved.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">compression</code></em></dt>

     <dd>

      <p class="para">
       This should be one of <em>Phar::NONE</em> for no whole-archive
       compression, <em>Phar::GZ</em> for zlib-based compression, and
       <em>Phar::BZ2</em> for bzip-based compression.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">extension</code></em></dt>

     <dd>

      <p class="para">
       This parameter is used to override the default file extension for a
       converted archive.  Note that <em>.phar</em> cannot be used
       anywhere in the filename for a non-executable tar or zip archive.
      </p>
      <p class="para">
       If converting to a tar-based phar archive, the
       default extensions are <em>.tar</em>, <em>.tar.gz</em>,
       and <em>.tar.bz2</em> depending on specified compression.
       For zip-based archives, the
       default extension is <em>.zip</em>.
      </p>
     </dd>

    
   </dl>

  </p>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-phar.converttodata-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The method returns a <a href="class.phardata.html" class="classname">PharData</a> object on success and throws an
   exception on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phar.converttodata-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   This method throws <a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a> when unable
   to compress, an unknown compression method has been specified, the requested
   archive is buffering with <span class="function"><a href="phar.startbuffering.html" class="function">Phar::startBuffering()</a></span> and
   has not concluded with <span class="function"><a href="phar.stopbuffering.html" class="function">Phar::stopBuffering()</a></span>, 
   and a <a href="class.pharexception.html" class="classname">PharException</a> if any problems are encountered
   during the phar creation process.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phar.converttodata-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-644">
    <p><strong>Example #1 A <span class="function"><strong>Phar::convertToData()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Using Phar::convertToData():
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tarphar&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar.tar'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;note&nbsp;that&nbsp;myphar.phar.tar&nbsp;is&nbsp;*not*&nbsp;unlinked<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;convert&nbsp;it&nbsp;to&nbsp;the&nbsp;non-executable&nbsp;tar&nbsp;file&nbsp;format<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;creates&nbsp;myphar.tar<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertToData</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;convert&nbsp;to&nbsp;non-executable&nbsp;zip&nbsp;format,&nbsp;creates&nbsp;myphar.zip<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$zip&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">ZIP</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;create&nbsp;myphar.tbz<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tgz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">TAR</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">BZ2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'.tbz'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;creates&nbsp;myphar.phar.tgz<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$phar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tarphar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertToData</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">PHAR</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;throws&nbsp;exception<br /></span><span style="color: #007700">}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;handle&nbsp;the&nbsp;error&nbsp;here<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-phar.converttodata-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="phar.converttoexecutable.html" class="function" rel="rdfs-seeAlso">Phar::convertToExecutable()</a> - Convert a phar archive to another executable phar archive file format</span></li>
    <li class="member"><span class="function"><a href="phardata.converttoexecutable.html" class="function" rel="rdfs-seeAlso">PharData::convertToExecutable()</a> - Convert a non-executable tar/zip archive to an executable phar archive</span></li>
    <li class="member"><span class="function"><a href="phardata.converttodata.html" class="function" rel="rdfs-seeAlso">PharData::convertToData()</a> - Convert a phar archive to a non-executable tar or zip file</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="phar.construct.html">Phar::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="phar.converttoexecutable.html">Phar::convertToExecutable</a></div>
 <div class="up"><a href="class.phar.html">Phar</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
